import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    count: 0,
    homeTabActive: 0, // 首页tab
    userInfo: {
      realName: '',
      staffId: '',
    },
    menuList: [
      {
        name: "首页",
        type: "0",
        list: [
          {
            name: "公告",
            path: "/notice",
          },
        ],
      },
      {
        name: "申请服务",
        type: "1",
        list: [],
      },
      {
        name: "审批",
        type: "2",
        list: [],
      },
      {
        name: "查询",
        type: "3",
        list: [],
      },
    ]
  },
  mutations: {
    increment(state) {
      state.count++;
    },
    setHomeTabActive(state, value) { // 新增
      state.homeTabActive = value;
    },
    setUserInfo(state, value) { // 新增
      state.userInfo = value;
    },
    updateMenuList(state, newList) {
      state.menuList = newList;
    }
  },
  actions: {
    incrementAsync({ commit }) {
      setTimeout(() => {
        commit('increment');
      }, 1000);
    },
    updateHomeTabActive({ commit }, value) { // 异步操作
      commit('setHomeTabActive', value);
    }
  },
  getters: {
    currentCount: state => state.count,
    getHomeTabActive: state => state.homeTabActive, // 获取状态的方法
    getUserInfo: state => state.userInfo
  }
});

export default store;
